﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Employeer/Employeer.master" Title="npljobs.com || Profile Information"
    CodeFile="EmployeerEntry.aspx.cs" Inherits="Employeer_EmployeerEntry" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="contentBody" ContentPlaceHolderID="MainContent" runat="server">
    <script src="../Scripts/jquery-ui.min.js"></script>
    <asp:HiddenField ID="hfContactPersonID" runat="server" />
    <asp:UpdatePanel ID="UpdatePanel3" runat="server">
        <ContentTemplate>
            <div style="display: block; margin-bottom: 10px" class="row-block-width orange-gradiant">
                <h3 class="panel-title text-center">Profile info.</h3>
            </div>
            <div class="RowBlockStyle row-block-inner">
                <div class="RowBlockStyle row row-block-color">
                    <div class="RowLeft">
                        <asp:UpdatePanel runat="server" ID="UpdatePanel4" UpdateMode="Conditional">
                            <ContentTemplate>
                                <script type="text/javascript">
                                    var fileuploaded;
                                    function uploadcomplete(sender, args) {
                                        var filesizeuploaded = parseInt(args.get_length());
                                        if (filesizeuploaded > 200000) {
                                            var updateProgress = $get('<%= UpdateProgress1.ClientID %>');
                                            updateProgress.style.display = "none";
                                            $("#<%= lblStatus.ClientID%>").html('File should be less then 200 KB');
                                            $("#<%= lblStatus.ClientID%>").css("color", "#EA2525");
                                            $("#<%= lblStatus.ClientID%>").show();
                                            return;
                                        }
                                        else {
                                            fileuploaded = args.get_fileName();
                                            $("#<%= imgEmployeerImage.ClientID%>").attr("src", "/<%= CompanyImageFolder %>/" + "Emp_<%= EmployeerID %>_" + fileuploaded);
                                            var updateProgress = $get('<%= UpdateProgress1.ClientID %>');
                                            updateProgress.style.display = "none";
                                            $("#<%= lblStatus.ClientID%>").html('Logo Uploaded Successfully.');
                                            $("#<%= lblStatus.ClientID%>").css("color", "#66CC00");
                                            $("#<%= lblStatus.ClientID%>").show();
                                        }
                                    }

                                    function uploadStart(sender, args) {
                                        $.ajax({
                                            type: "POST",
                                            url: "EmployeerEntry.aspx/RedirectJobSeeker",
                                            data: JSON.stringify({}),
                                            contentType: "application/json; charset=utf-8",
                                            dataType: "json",
                                            cache: false,
                                            async: false,
                                            success: function (msg) {
                                                var flag = msg.d;
                                                if (flag == true) {
                                                    window.location.href = "../JobSeeker/EditProfile.aspx";
                                                    return;
                                                }
                                            }
                                        });
                                        var filename = args.get_fileName();
                                        var filext = filename.substring(filename.lastIndexOf(".") + 1);
                                        if (filext == "jpg" || filext == "gif" || filext == "png" || filext == "JPG" || filext == "GIF" || filext == "PNG") {
                                            var updateProgress = $get('<%= UpdateProgress1.ClientID %>');
                                            updateProgress.style.display = "block";
                                            return true;
                                        }
                                        else {
                                            var err = new Error();
                                            err.name = 'My API Input Error';
                                            err.message = 'Only .jpg,.gif,.png  files';
                                            $get('imgEmployeerImage').src = "UploadedCompanyImage/";
                                            throw (err);
                                            return false;
                                        }
                                    }
                                    function uploaderror(sender, args) {
                                        alert(args.get_errorMessage());
                                    }
                                </script>
                                <div>
                                    <asp:Image runat="server" ID="imgEmployeerImage" ImageUrl="../Images/company-photo.png" class="upload-photo-image" />
                                </div>
                                <div style="margin-top: 10px; margin-left: 5px;">
                                    <div>
                                        <ajaxToolkit:AsyncFileUpload ID="asyncupload" runat="server" OnClientUploadComplete="uploadcomplete"
                                            OnClientUploadStarted="uploadStart" OnUploadedComplete="asynPictureUpload_UploadedComplete"
                                            CompleteBackColor="Green" UploaderStyle="Modern" UploadingBackColor="" OnClientUploadError="uploaderror"
                                            Width="160px" CssClass="FileUploadClass" />
                                    </div>
                                    <div>
                                    </div>
                                </div>
                                <asp:Label ID="lblStatus" runat="server" Style="font-family: Arial; font-size: small;"></asp:Label>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                        <asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="UpdatePanel4" runat="server">
                            <ProgressTemplate>
                                <img src="../Images/indicator.gif" alt="Loading.." />
                            </ProgressTemplate>
                        </asp:UpdateProgress>
                    </div>
                    <div class="RowRight form-row">
                        <div class="ControlDiv manage-profile">
                            <label class="labelStyle2">
                                Company Name&nbsp;<small>*</small></label>
                            <div class="col-md-6">
                                <asp:TextBox ID="txtCompanyName" CssClass="TextBoxStyle form-control" runat="server" MaxLength="100" placeholder="Enter Company Name"> </asp:TextBox>
                            </div>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtCompanyName" CssClass="required-field"
                                ErrorMessage="Company name missing" Text="*" EnableClientScript="true"></asp:RequiredFieldValidator>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="labelStyle2">
                                Business Type&nbsp;<small>*</small></label>
                            <div class="col-md-6">
                                <asp:DropDownList ID="ddlCompanyType" CssClass="formddl" runat="server" AppendDataBoundItems="true">
                                    <asp:ListItem Value="-1" Text="---Select a Company Type--"></asp:ListItem>
                                </asp:DropDownList>
                            </div>
                            <asp:RequiredFieldValidator ID="reqCompanyType" runat="server" ControlToValidate="ddlCompanyType" CssClass="required-field"
                                ErrorMessage="Company type missing" Text="*" EnableClientScript="true" InitialValue="-1"></asp:RequiredFieldValidator>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="labelStyle2">
                                Employee Range&nbsp;<small>*</small></label>
                            <div class="col-md-6">
                                <asp:DropDownList ID="ddlRangeOfEmployeer" CssClass="formddl" runat="server" AppendDataBoundItems="true">
                                    <asp:ListItem Value="-1" Text="---Range of employees--"></asp:ListItem>
                                </asp:DropDownList>
                            </div>
                            <asp:RequiredFieldValidator ID="reqRangeOfEmployeer" runat="server" ControlToValidate="ddlRangeOfEmployeer" CssClass="required-field"
                                ErrorMessage="Employee range missing" Text="*" EnableClientScript="true" InitialValue="-1"></asp:RequiredFieldValidator>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="labelStyle2">
                                Company Description&nbsp;<small>*</small></label>
                            <div class="col-md-6">
                                <asp:TextBox ID="txtCompanyDescription" CssClass="TextBoxStyle form-control" TextMode="MultiLine" MaxLength="200"
                                    runat="server" Height="80px" placeholder="Enter company description"></asp:TextBox>
                            </div>
                            <asp:RequiredFieldValidator ID="regCompanyDescription" runat="server" ControlToValidate="txtCompanyDescription" CssClass="required-field"
                                ErrorMessage="Company Description missing" Text="*" EnableClientScript="true"></asp:RequiredFieldValidator>
                        </div>
                        <div class="ControlDiv" style="display: none;">
                            <label class="labelStyle2">
                                Industry&nbsp;<small>*</small></label>
                            <asp:DropDownList CausesValidation="true" ID="ddlIndustry" CssClass="formddl" runat="server"
                                AppendDataBoundItems="true">
                                <asp:ListItem Value="-1" Text="---Select an industry--"></asp:ListItem>
                            </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="reqValIndustry" runat="server" ControlToValidate="ddlIndustry" CssClass="required-field"
                                ErrorMessage="Industry missing 1" Text="*"></asp:RequiredFieldValidator>
                        </div>
                    </div>
                </div>
                <div class="RowBlockStyle">
                    <div class="GroupHeaderStyle">
                        <span>Contact information</span>
                    </div>
                    <div class="DetailsStyle row row-block-color form-row">
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Address&nbsp;<small>*</small></label>
                            <div class="col-md-9">
                                <asp:TextBox ID="txtAddress" CssClass="text-box-style-col-2 form-control" TextMode="MultiLine" runat="server"
                                    Height="55px" placeholder="Enter address"></asp:TextBox>
                            </div>
                            <asp:RequiredFieldValidator ID="reqAddress" runat="server" ControlToValidate="txtAddress" CssClass="required-field"
                                ErrorMessage="Address missing" Text="*" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Country&nbsp;<small>*</small></label>
                            <div class="col-md-9">
                                <asp:DropDownList ID="ddlCountry" CssClass="form-ddl-col-2" runat="server" AutoPostBack="true"
                                    AppendDataBoundItems="true" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">
                                    <asp:ListItem Value="-1" Text="Select a country"></asp:ListItem>
                                </asp:DropDownList>
                            </div>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="ddlCountry" CssClass="required-field"
                                ErrorMessage="Country missing" Text="*" InitialValue="-1" EnableClientScript="true"
                                SetFocusOnError="true"></asp:RequiredFieldValidator>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                City&nbsp;<small>*</small></label>
                            <div class="col-md-9">
                                <asp:DropDownList ID="ddlCity" CssClass="form-ddl-col-2" runat="server">
                                    <asp:ListItem Value="-1" Text="Select a city"></asp:ListItem>
                                </asp:DropDownList>
                                <asp:TextBox ID="txtCity" runat="server" Visible="false" MaxLength="100" CssClass="text-box-style-col-2 form-control"></asp:TextBox>
                            </div>
                            <asp:RequiredFieldValidator ID="reqCity" runat="server" ControlToValidate="ddlCity" CssClass="required-field"
                                ErrorMessage="City missing" Text="*" InitialValue="-1" EnableClientScript="true"
                                SetFocusOnError="true"></asp:RequiredFieldValidator>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Phone</label>
                            <div class="col-md-9">
                                <asp:TextBox ID="txtPhone" CssClass="text-box-style-col-2 form-control" runat="server" MaxLength="20" placeholder="Enter phone" />
                            </div>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Mobile phone&nbsp;<small>*</small></label>
                            <div class="col-md-9">
                                <asp:TextBox ID="txtMobilePhone" CssClass="text-box-style-col-2 form-control" runat="server" MaxLength="20" placeholder="Enter mobile phone" />
                            </div>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator15" runat="server" ControlToValidate="txtMobilePhone" CssClass="required-field"
                                ErrorMessage="Mobile Phone missing" Text="*" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Fax</label>
                            <div class="col-md-9">
                                <asp:TextBox ID="txtFax" CssClass="text-box-style-col-2 form-control" runat="server" placeholder="Enter fax" />
                            </div>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Website url&nbsp;<small>*</small></label>
                            <div class="col-md-9">
                                <asp:TextBox ID="txtWebsiteUrl" CssClass="text-box-style-col-2 form-control" runat="server" placeholder="Enter website url" />
                            </div>
                            <asp:RequiredFieldValidator ID="reqWebsiteUrl" runat="server" ControlToValidate="txtWebsiteUrl" CssClass="required-field"
                                ErrorMessage="URL missing" Text="*" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"
                                ControlToValidate="txtWebsiteUrl" ErrorMessage="Invalid URL!" Text="*" EnableClientScript="true" CssClass="required-field"
                                SetFocusOnError="true"></asp:RegularExpressionValidator>
                            <label class="label-style-col-2">
                                &nbsp;</label>
                            <div class="col-md-9">e.g : http(s)://www.abc.com</div>
                        </div>
                    </div>
                </div>
                <div class="RowBlockStyle">
                    <div class="GroupHeaderStyle">
                        <span>Contact person</span>
                    </div>
                    <div class="DetailsStyle row row-block-color form-row">
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2" style="color: black;">
                                [To manage multiple contacts]</label>
                            <div class="buttonSpace">
                                <asp:Button ID="btnSelectContactPerson" Text="" runat="server" Width="108px" Height="45px" CssClass="edit-button" OnClientClick="return false;"
                                    OnClick="btnSelectContactPerson_Click" />
                            </div>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Title</label>
                            <div class="col-md-9">
                                <asp:DropDownList ID="ddlTitle" CssClass="form-ddl-col-2 disabled-cursor disabled-color" runat="server" Enabled="false" AppendDataBoundItems="true"
                                    DataTextField="Name" DataValueField="ID">
                                    <asp:ListItem Value="-1" Text="---Select a title--"></asp:ListItem>
                                    <asp:ListItem Value="1" Text="Mr."></asp:ListItem>
                                    <asp:ListItem Value="2" Text="Mrs."></asp:ListItem>
                                    <asp:ListItem Value="3" Text="Miss."></asp:ListItem>
                                    <asp:ListItem Value="4" Text="Ms."></asp:ListItem>
                                </asp:DropDownList>
                            </div>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                First name</label>
                            <div class="col-md-9">
                                <asp:TextBox ID="txtFirstName" Enabled="false" CssClass="text-box-style-col-2 disabled-cursor" runat="server" />
                            </div>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Last bame</label>
                            <div class="col-md-9">
                                <asp:TextBox ID="txtLastName" Enabled="false" CssClass="text-box-style-col-2 disabled-cursor" runat="server" />
                            </div>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Designation</label>
                            <div class="col-md-9">
                                <asp:DropDownList ID="ddlDesignation" CssClass="form-ddl-col-2 disabled-cursor disabled-color" runat="server" AppendDataBoundItems="true"
                                    Enabled="false">
                                    <asp:ListItem Value="-1" Text="---Select a title--"></asp:ListItem>
                                </asp:DropDownList>
                            </div>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Email address</label>
                            <div class="col-md-9">
                                <asp:TextBox ID="txtEmail" Enabled="false" CssClass="text-box-style-col-2 disabled-cursor" runat="server" />
                            </div>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Contact number</label>
                            <div class="col-md-9">
                                <asp:TextBox ID="txtContactNumber" Enabled="false" CssClass="text-box-style-col-2 disabled-cursor" runat="server" />
                            </div>
                        </div>
                        <div class="ControlDiv manage-profile">
                            <label class="label-style-col-2">
                                Alternative number</label>
                            <div class="col-md-9">
                                <asp:TextBox ID="txtAlternativeNumber" Enabled="false" CssClass="text-box-style-col-2 disabled-cursor" runat="server"> </asp:TextBox>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="RowBlockStyle" style="width: 100%;">
                    <div class="row row-block-color form-row">
                        <div class="ControlDiv manage-profile">
                            <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="<b>Invalid inputs</b>"
                                ShowMessageBox="false" DisplayMode="BulletList" ShowSummary="true" Style="margin-left: 350px;" />
                            <asp:Label ID="lblMsg" runat="server" ForeColor="Green" Font-Bold="true" Visible="false" Style="text-align: center; display: block; margin-top: 10px;">
                            </asp:Label>
                        </div>
                    </div>
                </div>
                <div class="RowBlockStyle" style="width: 100%;">
                    <div style="float: right; margin-top: 10px;">
                        <span class="float-shadow">
                            <asp:Button runat="server" Text="SAVE" ID="btnSaveEmployeerEntry" OnClick="btnSaveEmployeerEntry_Click"
                                CssClass="btn btn-primary orange-gradiant float-shadow" />
                        </span>
                        <span class="float-shadow">
                            <asp:Button ID="btnCancelEmployeerEntry" Text="CANCEL" runat="server" CssClass="btn btn-primary float-shadow blue-gradiant" Visible="false"
                                OnClientClick="Cancelation(); return false;" />
                        </span>
                    </div>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
    <p id="back-top" style="display:none;">
        <a href="#top"><span></span>Back to top</a>
    </p>
    <asp:UpdateProgress ID="UpdateProgress2" AssociatedUpdatePanelID="UpdatePanel3" runat="server">
        <ProgressTemplate>
            <div style="float: right; margin-right: 10px;">
                <img src="../Images/please_wait.gif" alt="Saving.." />
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
    <div id="contact_person_modal_dialog" style="display: none">
        <div id="ContactFields">
            <div class="RowBlockStyle RowBlockFull">
                <div class="DetailsStyle">
                    <div class="ControlDiv">
                        <input type="hidden" id="hdnEmployerID" />
                        <input type="hidden" id="hdnContactPersonID" />
                        <label class="label-style">
                            Title</label>
                        <asp:DropDownList ID="ddlPopupTitle" CssClass="form-ddl" runat="server" AppendDataBoundItems="true"
                            DataTextField="Name" DataValueField="ID">
                            <asp:ListItem Value="-1" Text="---Select a title--"></asp:ListItem>
                            <asp:ListItem Value="1" Text="Mr."></asp:ListItem>
                            <asp:ListItem Value="2" Text="Mrs."></asp:ListItem>
                            <asp:ListItem Value="3" Text="Miss."></asp:ListItem>
                            <asp:ListItem Value="4" Text="Ms."></asp:ListItem>
                        </asp:DropDownList>
                    </div>
                    <div class="ControlDiv">
                        <label class="label-style">
                            First name&nbsp;<small style="color: Blue;">*</small></label>
                        <asp:TextBox ID="txtPopupFirstName" CssClass="text-box-style" runat="server" MaxLength="50" placeholder="Enter first name" />
                        <span class="RequiredMessage">*</span>
                    </div>
                    <div class="ControlDiv">
                        <label class="label-style">
                            Last name&nbsp;<small style="color: Blue;">*</small></label>
                        <asp:TextBox ID="txtPopupLastName" CssClass="text-box-style" runat="server" MaxLength="50" placeholder="Enter last name" />
                        <span class="RequiredMessage">*</span>
                    </div>
                    <div class="ControlDiv">
                        <label class="label-style">
                            Contact number&nbsp;<small style="color: Blue;">*</small></label>
                        <asp:TextBox ID="txtPopupContactNumber" CssClass="text-box-style" runat="server" MaxLength="50" placeholder="Enter contact number" />
                        <span class="RequiredMessage">*</span>
                    </div>
                    <div class="ControlDiv">
                        <label class="label-style">
                            Alternative Number</label>
                        <asp:TextBox ID="txtPopupAlternativeContactNumber" CssClass="text-box-style" runat="server"
                            MaxLength="50" placeholder="Enter alternative number" />
                    </div>
                    <div class="ControlDiv">
                        <label class="label-style">
                            Designation</label>
                        <asp:DropDownList ID="ddlPopupDesignation" CssClass="form-ddl" runat="server" AppendDataBoundItems="true">
                            <asp:ListItem Value="-1" Text="---Select a title--"></asp:ListItem>
                        </asp:DropDownList>
                    </div>
                    <div class="ControlDiv">
                        <label class="label-style">
                            Email&nbsp;<small style="color: Blue;">*</small></label>
                        <asp:TextBox ID="txtPopupEmail" CssClass="text-box-style" runat="server" MaxLength="100" placeholder="Enter email address" />
                        <span class="RequiredMessage">*</span>
                    </div>
                </div>
            </div>
            <div class="RowBlockStyle RowBlockFull">
                <div style="float: left; margin-left: 10px;">
                    <asp:Button runat="server" Text="SET CONTACT" ID="btnSetContact" CssClass="GreenCommandStyle PopupCommandStyle"
                        Style="width: 115px; visibility: hidden;" />
                </div>
                <div style="float: right; margin-right: 10px; margin-bottom: 10px; margin-top: 10px;">
                    <span class="float-shadow">
                        <asp:Button ID="btnPopupClear" Text="ADD NEW" runat="server" CssClass="btn btn-primary float-shadow blue-gradiant" OnClientClick="return false;" />
                    </span>
                    <span class="float-shadow">
                        <asp:Button runat="server" Text="SAVE" ID="btnPopupSave" CssClass="btn btn-primary orange-gradiant float-shadow" OnClientClick="return false;" />
                    </span>
                </div>
            </div>
        </div>
        <br />
        <h4 class="contact-person-hind-msg">Please, choose contact person and close window.</h4>
        <div id="ContactLists" class="RowBlockStyle RowBlockFull">
            <table id="tblPopupContactPerson" class="tblPopupContactPerson">
                <thead>
                    <tr>
                        <th>&nbsp;
                        </th>
                        <th>Title
                        </th>
                        <th>First name
                        </th>
                        <th>Last name
                        </th>
                        <th>Contact number
                        </th>
                        <th style="width: 80px;">Actions
                        </th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
            <br />
        </div>
    </div>
    <script type="text/javascript">
        function CheckValidation() {
            var required = false;
            if ($("#<%=txtPopupFirstName.ClientID %>").val().trim().length < 1) {
                $("#<%=txtPopupFirstName.ClientID %>").next().css("display", "block");
                required = true;
            }
            else
                $("#<%=txtPopupFirstName.ClientID %>").next().css("display", "none");

            if ($("#<%=txtPopupLastName.ClientID %>").val().trim().length < 1) {
                $("#<%=txtPopupLastName.ClientID %>").next().css("display", "block");
                required = true;
            }
            else
                $("#<%=txtPopupLastName.ClientID %>").next().css("display", "none");

            if ($("#<%=txtPopupContactNumber.ClientID %>").val().trim().length < 1) {
                $("#<%=txtPopupContactNumber.ClientID %>").next().css("display", "block");
                required = true;
            }
            else
                $("#<%=txtPopupContactNumber.ClientID %>").next().css("display", "none");

            if ($("#<%=txtPopupEmail.ClientID %>").val().trim().length < 1) {
                $("#<%=txtPopupEmail.ClientID %>").next().css("display", "block");
                required = true;
            }
            else if (!validateEmail($("#<%=txtPopupEmail.ClientID %>").val())) {
                $("#<%=txtPopupEmail.ClientID %>").next().css("display", "block");
                required = true;
            }
            else {
                $("#<%=txtPopupEmail.ClientID %>").next().css("display", "none");
            }

        return required;
    }

    function ClearFieldsValue() {
        $("#hdnEmployerID").val("");
        $("#hdnContactPersonID").val("");
        $("#<%=ddlPopupTitle.ClientID %>").val("-1");
        $("#<%=ddlPopupTitle.ClientID %>").next().css("display", "none");
        $("#<%=txtPopupFirstName.ClientID %>").val("");
        $("#<%=txtPopupFirstName.ClientID %>").next().css("display", "none");
        $("#<%=txtPopupLastName.ClientID %>").val("");
        $("#<%=txtPopupLastName.ClientID %>").next().css("display", "none");
        $("#<%=txtPopupContactNumber.ClientID %>").val("");
        $("#<%=txtPopupContactNumber.ClientID %>").next().css("display", "none");
        $("#<%=txtPopupAlternativeContactNumber.ClientID %>").val("");
        $("#<%=ddlPopupDesignation.ClientID %>").val("-1");
        $("#<%=txtPopupEmail.ClientID %>").val("");
    }

    function DeleteContact(contactPersonID) {
        $.ajax({
            type: "POST",
            url: "EmployeerEntry.aspx/DeleteContactPerson",
            data: JSON.stringify({ "contactPersonID": contactPersonID }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            async: false,
            success: function (msg) {
                var status = msg.d;
                if (status === 1) {
                    $("#" + contactPersonID).parent().remove();
                    ClearFieldsValue();
                }
            },
            error: function (data, status, jqXHR) {
                console.log(status);
            }
        });
    }

    function LoadContact(contactPersonID) {
        $.ajax({
            type: "POST",
            url: "EmployeerEntry.aspx/GetContactPerson",
            data: JSON.stringify({ "contactPersonID": contactPersonID }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            async: false,
            success: function (msg) {
                var obj = JSON.parse(msg.d);
                $("#hdnEmployerID").val(obj.EmployeerID);
                $("#hdnContactPersonID").val(obj.ContactPersonID);
                if (obj.TitleID == 0)
                    $("#<%=ddlPopupTitle.ClientID %>").val("-1");
                else
                    $("#<%=ddlPopupTitle.ClientID %>").val(obj.TitleID);
                $("#<%=txtPopupFirstName.ClientID %>").val(obj.FirstName);
                $("#<%=txtPopupLastName.ClientID %>").val(obj.LastName);
                $("#<%=txtPopupContactNumber.ClientID %>").val(obj.ContactNumber);
                $("#<%=txtPopupAlternativeContactNumber.ClientID %>").val(obj.AlternativeNumber);
                if (obj.DesignationID == 0)
                    $("#<%=ddlPopupDesignation.ClientID %>").val("-1");
                else
                    $("#<%=ddlPopupDesignation.ClientID %>").val(obj.DesignationID);
                $("#<%=txtPopupEmail.ClientID %>").val(obj.Email);
            },
            error: function (data, status, jqXHR) {
                console.log('LoadContact');
            }
        });
    }

    function InIEvent() {
        $("#<%=txtPhone.ClientID %>").ForceNumberOnly();
        $("#<%=txtMobilePhone.ClientID %>").ForceNumberOnly();
        $("#<%=txtFax.ClientID %>").ForceNumberOnly();

        $("#<%=txtPopupContactNumber.ClientID %>").ForceNumberOnly();
        $("#<%=txtPopupAlternativeContactNumber.ClientID %>").ForceNumberOnly();
    }

    $(document).ready(InIEvent);

    $(document).ready(function () {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(InIEvent);

        $("#contact_person_modal_dialog").dialog({
            title: "Contact Person",
            modal: true,
            autoOpen: false,
            width: 700,
            height: 750,
            resizable: false,
            appendTo: "form",
            buttons: {
            },
            close: function () {
                SetContact();
            }
        });

        function LoadContactsByEmployer(currentContactPersonID) {
            $.ajax({
                type: "POST",
                url: "EmployeerEntry.aspx/GetContactsPerson",
                data: JSON.stringify({}),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                cache: false,
                async: false,
                success: function (msg) {
                    var obj = JSON.parse(msg.d);
                    var html = "";
                    $.each(obj, function (key, value) {
                        var title = "";
                        if (value.TitleID === 1)
                            title = "Mr.";
                        else if (value.TitleID === 2)
                            title = "Mrs.";
                        else if (value.TitleID === 3)
                            title = "Miss.";
                        else if (value.TitleID === 4)
                            title = "Ms.";

                        html = html + "<tr id='" + value.EmployeerID + "'>";
                        html = html + "<input type='hidden' id='" + value.ContactPersonID + "' value='" + value.ContactPersonID + "' />";
                        if (currentContactPersonID == value.ContactPersonID)
                            html = html + "<td><input id='" + value.ContactPersonID + "' type='radio' name='group1' checked></td>";
                        else
                            html = html + "<td><input id='" + value.ContactPersonID + "' type='radio' name='group1'></td>";
                        html = html + "<td>" + title + "</td>";
                        html = html + "<td>" + value.FirstName + "</td>";
                        html = html + "<td>" + value.LastName + "</td>";
                        html = html + "<td>" + value.ContactNumber + "</td>";
                        html = html + "<td><a href='javascript:LoadContact(" + value.ContactPersonID + ");'>Edit</a>|<a href='javascript:DeleteContact(" + value.ContactPersonID + ");'>Delete</a></td>";
                        html = html + "</tr>";
                    });
                    $("#tblPopupContactPerson >tbody").html('');
                    $("#tblPopupContactPerson >tbody").append(html);
                },
                error: function (data, status, jqXHR) {
                    console.log('LoadContactsByEmployer');
                }
            });
        }

        function SetContact() {
            $("#<%=hfContactPersonID.ClientID %>").val("");
            $("#<%=ddlTitle.ClientID %>").val("");
            $("#<%=txtFirstName.ClientID %>").val("");
            $("#<%=txtLastName.ClientID %>").val("");
            $("#<%=ddlDesignation.ClientID %>").val("");
            $("#<%=txtEmail.ClientID %>").val("");
            $("#<%=txtContactNumber.ClientID %>").val("");
            $("#<%=txtAlternativeNumber.ClientID %>").val("");
            
            var radio = $("input[name='group1']:checked");
            var contactPersonID = radio.attr('id');
            if (typeof (contactPersonID) != 'undefined') {
                $.ajax({
                    type: "POST",
                    url: "EmployeerEntry.aspx/GetContactPerson",
                    data: JSON.stringify({ "contactPersonID": contactPersonID }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    cache: false,
                    async: false,
                    success: function (msg) {
                        var obj = JSON.parse(msg.d);
                        $("#<%=hfContactPersonID.ClientID %>").val(obj.ContactPersonID);
                        $("#<%=ddlTitle.ClientID %>").val(obj.TitleID);
                        $("#<%=txtFirstName.ClientID %>").val(obj.FirstName);
                        $("#<%=txtLastName.ClientID %>").val(obj.LastName);
                        $("#<%=ddlDesignation.ClientID %>").val(obj.DesignationID);
                        $("#<%=txtEmail.ClientID %>").val(obj.Email);
                        $("#<%=txtContactNumber.ClientID %>").val(obj.ContactNumber);
                        $("#<%=txtAlternativeNumber.ClientID %>").val(obj.AlternativeNumber);
                    },
                    error: function (data, status, jqXHR) {
                        console.log('SetContact');
                    }
                });
            }
        }

        $("#<%=btnSaveEmployeerEntry.ClientID %>").live('click', function () {
            $("#<%=lblMsg.ClientID %>").html('');
        });

        $("#<%=btnSelectContactPerson.ClientID %>").live('click', function () {
            var currentContactPersonID = $("#<%= hfContactPersonID.ClientID %>").val();
            if (typeof (currentContactPersonID) != 'undefined') {
                LoadContactsByEmployer(currentContactPersonID);
                $('#contact_person_modal_dialog').dialog('open');
            }
            return false;
        });

        $("#<%=btnSetContact.ClientID %>").click(function () {
            SetContact();
            $('#contact_person_modal_dialog').dialog('close');
        });

        $("#<%=btnPopupSave.ClientID %>").click(function () {
            if (CheckValidation() == false) {
                var parms =
                {
                    "hdnEmployerID": $('#hdnEmployerID').val(),
                    "hdnContactPersonID": $('#hdnContactPersonID').val(),
                    "ddlPopupTitle": $('#<%=ddlPopupTitle.ClientID %>').val(),
                    "txtPopupFirstName": $('#<%=txtPopupFirstName.ClientID %>').val(),
                    "txtPopupLastName": $('#<%=txtPopupLastName.ClientID %>').val(),
                    "txtPopupContactNumber": $('#<%=txtPopupContactNumber.ClientID %>').val(),
                    "txtPopupAlternativeContactNumber": $('#<%=txtPopupAlternativeContactNumber.ClientID %>').val(),
                    "ddlPopupDesignation": $('#<%=ddlPopupDesignation.ClientID %>').val(),
                    "txtPopupEmail": $('#<%=txtPopupEmail.ClientID %>').val()
                };
                var obj = { parms: parms };
                $.ajax({
                    type: "POST",
                    url: "EmployeerEntry.aspx/SaveContactPerson",
                    data: JSON.stringify(obj),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        var status = msg.d;
                        if (status > 0) {
                            ClearFieldsValue();
                            $("#<%=ddlPopupTitle.ClientID %>").focus();
                            var currentContactPersonID = $("#<%= hfContactPersonID.ClientID %>").val();
                            if (typeof (currentContactPersonID) != 'undefined') {
                                LoadContactsByEmployer(currentContactPersonID);
                            }
                        }
                        else {
                            console.log('SaveContactPerson 01');
                        }
                    },
                    error: function (data, status, jqXHR) {
                        console.log('SaveContactPerson');
                    }
                });
            }
            return false;
        });

        $("#<%=btnPopupClear.ClientID %>").click(function () {
            ClearFieldsValue();
            $("#<%=ddlPopupTitle.ClientID %>").focus();
            return false;
        });
    });
    </script>
    <script src="../Scripts/jsEmployeerEntry.js"></script>
</asp:Content>
